<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('添加基类')"/>
</head>
<body>
<form class="layui-form" action="" onsubmit="return false">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">基类编码</label>
                <div class="layui-input-block">
                    <input type="text" name="code" lay-verify="required" lay-affix="clear" placeholder="请输入基类编码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">基类包名</label>
                <div class="layui-input-block">
                    <input type="text" name="packageName" lay-verify="required" lay-affix="clear" placeholder="请输入基类包名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">基类字段</label>
                <div class="layui-input-block">
                    <div class="layui-btn-container tag" name="fields" lay-filter="fields-filter" lay-newTag="true" lay-allowclose="true"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea  name="remark" lay-affix="clear" placeholder="备注" autocomplete="off" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="pear-btn pear-btn-md pear-btn-radius pear-btn-primary" lay-submit lay-filter="formDemo">确定</button>
                    <button type="reset" class="pear-btn pear-btn-md pear-btn-radius">取消</button>
                </div>
            </div>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    let prefix = "/baseEntity/";
    layui.use(['form','http','tag'], function () {
        const form = layui.form;
        let http = layui.http;
        let tag = layui.tag;
        let util = layui.util
        util.on({

        });

        tag.render("fields-filter", {
            skin: 'layui-btn pear-btn pear-btn-xs pear-btn-radius pear-btn-primary pear-btn-radius', //标签样式
            tagText: '<i class="layui-icon layui-icon-add-1"></i>添加' //标签添加按钮提示文本
        });
        tag.on('delete(fields-filter)', function(data) {
            console.log(this); //当前Tag标签所在的原始DOM元素
            console.log(data.index); //得到当前Tag的所在下标
            console.log(data.elem); //得到当前的Tag大容器
        });
        tag.on('add(fields-filter)', function(data) {
            console.log(this); //当前Tag标签所在的原始DOM元素
        })

        form.on('submit(formDemo)', function (data) {
            http.request({
                url: prefix+"save",
                contentType: http.contentType.json,
                data:data.field,
                method:"POST"
            }).then(res=>{
                layer.msg(res.message,{icon:1,time:1000},function(){
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("base-table");
                });
            }).catch(e=>{
                console.error(e)
            })
            return false;
        });
    });
</script>
</body>
</html>